home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 May / PCpro_2006_05.ISO / files / mobile / fma-2.0-stable-setup.exe / {app} / sframework / plugins / Winamp.vbs < prev    next >
Encoding:
Text File  |  2004-09-09  |  13.8 KB  |  384 lines

  1. 'FMA Script Framework Plugin
  2. 'Winamp
  3. 'This plugin controls WinAmp
  4.  
  5. 'TODO:
  6. '-Extend Seek dialogue (see carpediem, keep up to date with the tracks current position)
  7.  
  8. Const WINAMP_SEARCH_ARTIST_MATCH  = 0
  9. Const WINAMP_SEARCH_ARTIST_SUBSTR = 1
  10. Const WINAMP_SEARCH_TITLE_MATCH   = 2
  11. Const WINAMP_SEARCH_TITLE_SUBSTR  = 3
  12. Const WINAMP_SEARCH_BOTH_MATCH    = 4
  13. Const WINAMP_SEARCH_BOTH_SUBSTR   = 5
  14. Const WINAMP_SEARCH_ONE_MATCH     = 6
  15. Const WINAMP_SEARCH_ONE_SUBSTR    = 7
  16.  
  17. Class Winamp
  18.     
  19.     Private m_Self
  20.     Private mainMenu
  21.     Private playListMenu
  22.     Private searchMenu
  23.     Public playlistExplorer
  24.     
  25.     'Some info about the plugin
  26.     Public Property Get SHOWABLE 'Do I have a menu?
  27.         SHOWABLE    = True
  28.     End Property
  29.     Public Property Get TITLE 'What's my name?
  30.         TITLE       = "WinAmp"
  31.     End Property
  32.     Public Property Get DESCRIPTION 'What's my purpose?
  33.         DESCRIPTION = "This plugin controls winamp. You may use the menu and the phones volume keys."
  34.     End Property
  35.     Public Property Get AUTHOR 'Who created me?
  36.         AUTHOR      = "dVrVm (also starring streawkceur)"
  37.     End Property
  38.     Public Property Get URL 'Were can I be found? Where can you get more information?
  39.         URL = "http://fma.xinium.com/"
  40.     End Property
  41.     
  42.     'Who am I?
  43.     Public Property Let Self (s)
  44.         m_Self = s
  45.         ' Some init stuff here:
  46.         If IsEmpty(Settings(Me, "Title"))          or Settings(Me, "Title") = ""          Then Settings(Me, "Title")          = "Winamp"
  47.         If IsEmpty(Settings(Me, "Exe"))            or Settings(Me, "Exe")   = ""          Then Settings(Me, "Exe")            = "C:\Program Files\Winamp\winamp.exe"
  48.         If IsEmpty(Settings(Me, "PlaylistFolder")) or Settings(Me, "PlaylistFolder") = "" Then Settings(Me, "PlaylistFolder") = Fso.GetParentFolderName(Settings(Me, "Exe"))
  49.         Set mainMenu     = New ManagedMenu
  50.         Set playListMenu = New ManagedMenu
  51.         Set searchMenu   = New ManagedMenu
  52.         'Init searchMenu
  53.         Dim llist, bi
  54.         Set llist = New LinkedList
  55.         bi = llist.BackInserter
  56.         bi.Item = Array("Browse Artists", m_Self & ".BrowseArtist")
  57.         bi.Item = Array("Search Artists", m_Self & ".SearchArtist")
  58.         bi.Item = Array("Search Titles",  m_Self & ".SearchTitle")
  59.         bi.Item = Array("Search Both",    m_Self & ".SearchBoth")
  60.         searchMenu.SetList llist
  61.         searchMenu.Title = "Search/Browse"
  62.     End Property
  63.     Public Property Get Self
  64.         Self = m_Self
  65.     End Property
  66.     
  67.     'Display me. Eventually put a menu on the screen
  68.     Sub Show()
  69.         'Set the PathExe, launch the program
  70.         If Fso.FileExists(Settings(Me, "Exe")) Then
  71.             ActiveXManager("WinampCOMLib.WinampCOMObj").PathExe = Fso.GetParentFolderName(Settings(Me, "Exe"))
  72.         Else
  73.             Debug.ErrorMsg m_Self & " - Init: File not found: " & Settings(Me, "Exe")
  74.         End If
  75.         
  76.         Dim llist, bi, state
  77.         Set llist = New LinkedList
  78.         bi = llist.BackInserter
  79.         If ActiveXManager("WinampCOMLib.WinampCOMObj").WinampState = True Then
  80.             state = ActiveXManager("WinampCOMLib.WinampCOMObj").GetSongState
  81.             If state = "Playing" Then
  82.                 bi.Item = Array("Restart",      Self & ".Play")
  83.             Else
  84.                 bi.Item = Array("Play",         Self & ".Play")
  85.             End If
  86.             If state = "Paused" Then
  87.                 bi.Item = Array("Resume",       Self & ".Pause")
  88.             Else
  89.                 bi.Item = Array("Pause",        Self & ".Pause")
  90.             End If
  91.             bi.Item = Array("Stop",           Self & ".Stopp")
  92.             bi.Item = Array("<< Prev Track ", Self & ".PrevTrack")
  93.             bi.Item = Array(">> Next Track ", Self & ".NextTrack")
  94.             bi.Item = Array("Volume",         Self & ".Volume")
  95.             bi.Item = Array("Show Playlist",  Self & ".Playlist")
  96.             bi.Item = Array("Load Playlist",  Self & ".LoadPlaylist")
  97.             bi.Item = Array("Search/Browse",  Self & ".SearchBrowse")
  98. '            bi.Item = Array("Seek",           Self & ".Seek")
  99.             If ActiveXManager("WinampCOMLib.WinampCOMObj").Shuffle Then
  100.                 bi.Item = Array("Shuffle Off",  Self & ".Shuffle")
  101.             Else
  102.                 bi.Item = Array("Shuffle On",   Self & ".Shuffle")
  103.             End If
  104.             If ActiveXManager("WinampCOMLib.WinampCOMObj").Repeat Then
  105.                 bi.Item = Array("Repeat Off",   Self & ".Repeat")
  106.             Else
  107.                 bi.Item = Array("Repeat On",    Self & ".Repeat")
  108.             End If
  109.             bi.Item = Array("Help",           Self & ".Help")
  110.             bi.Item = Array("Close",          Self & ".Close")
  111.         Else
  112.             bi.Item = Array("Launch",         Self & ".Launch")
  113.         End If
  114.         mainMenu.SetList llist
  115.         mainMenu.Title = TITLE
  116.         mainMenu.ShowMenu
  117.         
  118.         EventManager.RegisterEvent "MenuClose",      Self & ".ExitMenu", Me
  119.         EventManager.RegisterEvent "ConnectionLost", Self & ".ExitMenu", Me
  120.     End Sub
  121.     
  122.     Sub Launch
  123.         If Fso.FileExists(Settings(Me, "Exe")) Then
  124.             ActiveXManager("WinampCOMLib.WinampCOMObj").WinampState = True
  125.             'Shell.Exec Settings(Me, "Exe")
  126.             'Util.WaitForAppLoad Settings(Me, "Title"), 10000 'Give winamp max. 10 secs to load
  127.         Else
  128.             Debug.ErrorMsg Self & " - Launch: File not found: " & Settings(Me, "Exe")
  129.         End If
  130.         Show
  131.     End Sub
  132.     
  133.     Sub Close
  134.         ActiveXManager("WinampCOMLib.WinampCOMObj").WinampState = False
  135.         Show
  136.     End Sub
  137.     
  138.     Sub Play
  139.         ActiveXManager("WinampCOMLib.WinampCOMObj").Play
  140.         Show
  141.     End Sub
  142.     
  143.     Sub Pause
  144.         ActiveXManager("WinampCOMLib.WinampCOMObj").Pause
  145.         Show
  146.     End Sub
  147.     
  148.     Sub Stopp
  149.         ActiveXManager("WinampCOMLib.WinampCOMObj").Stop
  150.         Show
  151.     End Sub
  152.     
  153.     Sub PrevTrack
  154.         ActiveXManager("WinampCOMLib.WinampCOMObj").PreviousTrack
  155.         Show
  156.     End Sub
  157.     
  158.     Sub NextTrack
  159.         ActiveXManager("WinampCOMLib.WinampCOMObj").NextTrack
  160.         Show
  161.     End Sub
  162.     
  163.     Sub Shuffle
  164.         ActiveXManager("WinampCOMLib.WinampCOMObj").Shuffle = Not ActiveXManager("WinampCOMLib.WinampCOMObj").Shuffle
  165.         Show
  166.     End Sub
  167.     
  168.     Sub Repeat
  169.         ActiveXManager("WinampCOMLib.WinampCOMObj").Repeat = Not ActiveXManager("WinampCOMLib.WinampCOMObj").Repeat
  170.         Show
  171.     End Sub
  172.     
  173.     Sub VolUp
  174.         ActiveXManager("WinampCOMLib.WinampCOMObj").Volumeup
  175.     End Sub
  176.     Sub VolDn
  177.         ActiveXManager("WinampCOMLib.WinampCOMObj").VolumeDown
  178.     End Sub
  179.     
  180.     Sub VolUpPress
  181.         fma.AddTimer 60, Self & ".VolUp"
  182.     End Sub
  183.     Sub VolUpRelease
  184.         fma.DeleteTimer Self & ".VolUp"
  185.     End Sub
  186.     
  187.     Sub VolDnPress
  188.         fma.AddTimer 60, Self & ".VolDn"
  189.     End Sub
  190.     Sub VolDnRelease
  191.         fma.DeleteTimer Self & ".VolDn"
  192.     End Sub
  193.     
  194.     Sub Volume()
  195.         EmptyMenu.ShowMenu
  196.         am.Back = Self & ".VolumeQuit" 'Mangage the menu quit by ourselves
  197.         'Volume Up
  198.         KeyManager.RegisterKey KEY_VOLUP,    Self & ".VolUpPress",   STATE_PRESS,   Me
  199.         KeyManager.RegisterKey KEY_JOYUP,    Self & ".VolUpPress",   STATE_PRESS,   Me
  200.         KeyManager.RegisterKey KEY_JOYRIGHT, Self & ".VolUpPress",   STATE_PRESS,   Me
  201.         KeyManager.RegisterKey KEY_VOLUP,    Self & ".VolUpRelease", STATE_RELEASE, Me
  202.         KeyManager.RegisterKey KEY_JOYUP,    Self & ".VolUpRelease", STATE_RELEASE, Me
  203.         KeyManager.RegisterKey KEY_JOYRIGHT, Self & ".VolUpRelease", STATE_RELEASE, Me
  204.         'Volume Down
  205.         KeyManager.RegisterKey KEY_VOLDOWN,  Self & ".VolDnPress",   STATE_PRESS,   Me
  206.         KeyManager.RegisterKey KEY_JOYDOWN,  Self & ".VolDnPress",   STATE_PRESS,   Me
  207.         KeyManager.RegisterKey KEY_JOYLEFT,  Self & ".VolDnPress",   STATE_PRESS,   Me
  208.         KeyManager.RegisterKey KEY_VOLDOWN,  Self & ".VolDnRelease", STATE_RELEASE, Me
  209.         KeyManager.RegisterKey KEY_JOYDOWN,  Self & ".VolDnRelease", STATE_RELEASE, Me
  210.         KeyManager.RegisterKey KEY_JOYLEFT,  Self & ".VolDnRelease", STATE_RELEASE, Me
  211.         am.DlgMsgBox "Increase Volume: Joy-up,-right,Vol-up - Decrease volume: Joy-down,-left,Vol-down", 0
  212.     End Sub
  213.     Sub VolumeQuit()
  214.         KeyManager.DeregisterAll Me
  215.         MenuStack.Top.Quit 'Remove emtpy menu
  216.     End Sub
  217.     
  218.     
  219.     Sub ExitMenu ( sName )
  220.         If sName = TITLE Then
  221.             KeyManager.DeregisterAll Me
  222.             EventManager.DeregisterAll Me
  223.         End If
  224.     End Sub
  225.     
  226.     Sub Help()
  227.         EmptyMenu.ShowMenu
  228.         am.DlgMsgBox "The menu should be mostly self-explaining. Note that you can set Winamp's volume with your phones volume keys!", 0
  229.     End Sub
  230.     
  231.     Sub Playlist ()
  232.         Dim pList, pLbi, cnt, pageAndIndex
  233.         'Retrieve playlist
  234.         ActiveXManager("WinampCOMLib.WinampCOMObj").GetPlayList
  235.         Set pList = New LinkedList
  236.         pLbi = pList.BackInserter
  237.         For cnt = 0 To ActiveXManager("WinampCOMLib.WinampCOMObj").GetPlayListLength - 1
  238.             pLbi.Item = Array( getSong(cnt), Self & ".PlaySongShowPlaylist " & cnt)
  239.         Next
  240.         If pList.Count < 1 Then pLbi.Item = Array( "(empty)", "am.Update" )
  241.         playListMenu.Title = "Playlist"
  242.         playListMenu.SetList pList
  243.         pageAndIndex = playListMenu.GetPageAndIndexByItemIndex(ActiveXManager("WinampCOMLib.WinampCOMObj").GetPlayListPosition - 1)
  244.         playListMenu.ShowPage(pageAndIndex(0)) 'Show page of currently played song
  245.         am.Selected = pageAndIndex(1) + 1 'jump to song
  246.         am.Update
  247.     End Sub
  248.     
  249.     'Play song and show playlist again
  250.     Sub PlaySongShowPlaylist( i )
  251.     ActiveXManager("WinampCOMLib.WinampCOMObj").PlaySongByPosition(i)
  252.         Playlist
  253.     End Sub
  254.     
  255.     'Play song and show the search result again
  256.     Sub PlaySongShowSearch( i )
  257.     ActiveXManager("WinampCOMLib.WinampCOMObj").PlaySongByPosition(i)
  258.         am.Update
  259.     End Sub
  260.     
  261.     Private Function getSong(p)
  262.         Dim s, artist, title, mark
  263.         
  264.         artist = Trim(ActiveXManager("WinampCOMLib.WinampCOMObj").GetArtistbyPosition(p))
  265.         title  = Trim(ActiveXManager("WinampCOMLib.WinampCOMObj").GetSongTitlebyPosition(p))
  266.         If artist <> "" And title <> "" Then
  267.             s = artist & " - " & title
  268.         Else
  269.             s = artist & title
  270.         End If
  271.         s = Replace(s,"( ","(")
  272.         s = Replace(s," )",")")
  273.         s = Replace(s,"[ ","[")
  274.         s = Replace(s," ]","]")
  275.         
  276.         If (ActiveXManager("WinampCOMLib.WinampCOMObj").GetPlayListPosition - 1 = p) Then    'if P is current song being played
  277.           mark = ">" 'mark song
  278.         Else
  279.           mark = "  "
  280.         End If
  281.         getSong = mark & s
  282.     End Function
  283.     
  284.     Sub LoadPlaylist()
  285.         If PluginManager.IsClassImported("FileExplorer") Then
  286.             'Create a new FileExplorer and browse the playlist folder from the settings
  287.             Set playlistExplorer = Util.CreateObject("FileExplorer", Self & ".playlistExplorer")
  288.             playlistExplorer.ShowDir Settings(Me, "PlaylistFolder"), 0
  289.         Else
  290.             Debug.ErrorMsg Self & "You will need the FileExplorer plugin to select playlists!"
  291.         End If
  292.     End Sub
  293.     
  294.     Sub SearchBrowse()
  295.         searchMenu.ShowMenu
  296.     End Sub
  297.     
  298.     Sub Seek()
  299.         EmptyMenu.ShowMenu
  300.         ActiveXManager("WinampCOMLib.WinampCOMObj").SongPosParseTime = FALSE
  301.         ActiveXManager("WinampCOMLib.WinampCOMObj").SetLengthParseTime = FALSE
  302.         am.DlgPercent "Seek", Self & ".SeekResult", 10, 10 * (ActiveXManager("WinampCOMLib.WinampCOMObj").GetSongPosition / ActiveXManager("WinampCOMLib.WinampCOMObj").GetSongLength / 1000)
  303.     End Sub
  304.     Sub SeekResult( value, final )
  305.         If final = 1 Then
  306.             ActiveXManager("WinampCOMLib.WinampCOMObj").JumpToTime value * (ActiveXManager("WinampCOMLib.WinampCOMObj").GetSongLength / 10)
  307.             MenuStack.Top.Quit 'Remove emtpy menu
  308.         End If
  309.     End Sub
  310.     
  311.     Sub BrowseArtist()
  312.         Dim llist, bi, cnt, tempMenu
  313.         'Retrieve playlist
  314.         ActiveXManager("WinampCOMLib.WinampCOMObj").GetPlayList
  315.         Set llist = New LinkedList
  316.         bi = llist.BackInserter
  317.         For cnt = 0 To ActiveXManager("WinampCOMLib.WinampCOMObj").GetTotalUniqueArtist - 1
  318.             bi.Item = Array(Trim(ActiveXManager("WinampCOMLib.WinampCOMObj").GetUniqueArtist(cnt)), Self & ".BrowseTracksByArtistAndTitle " & WINAMP_SEARCH_ARTIST_MATCH & ", """ & Trim(ActiveXManager("WinampCOMLib.WinampCOMObj").GetUniqueArtist(cnt)) & """, Empty")
  319.         Next
  320.         If llist.Count < 1 Then bi.Item = Array( "(empty)", "am.Update" )
  321.         Set tempMenu = New ManagedMenu
  322.         tempMenu.Title = "Artists"
  323.         tempMenu.SetList llist
  324.         tempMenu.ShowMenu
  325.     End Sub
  326.     
  327.     Sub SearchArtist()
  328.         EmptyMenu.ShowMenu
  329.         am.DlgInputStr "Search artists", "Artists:", 16, "", Self & ".SearchArtistResult"
  330.     End Sub
  331.     Sub SearchArtistResult( input )
  332.         MenuStack.Pop 'Remove emtpy menu
  333.         BrowseTracksByArtistAndTitle WINAMP_SEARCH_ARTIST_SUBSTR, input, ""
  334.     End Sub
  335.     
  336.     Sub SearchTitle()
  337.         EmptyMenu.ShowMenu
  338.         am.DlgInputStr "Search titles", "Titles:", 16, "", Self & ".SearchTitleResult"
  339.     End Sub
  340.     Sub SearchTitleResult( input )
  341.         MenuStack.Pop 'Remove emtpy menu
  342.         BrowseTracksByArtistAndTitle WINAMP_SEARCH_TITLE_SUBSTR, "", input
  343.     End Sub
  344.     
  345.     Sub SearchBoth()
  346.         EmptyMenu.ShowMenu
  347.         am.DlgInputStr "Search both", "Artists/Titles:", 16, "", Self & ".SearchBothResult"
  348.     End Sub
  349.     Sub SearchBothResult( input )
  350.         MenuStack.Pop 'Remove emtpy menu
  351.         BrowseTracksByArtistAndTitle WINAMP_SEARCH_ONE_SUBSTR, input, input
  352.     End Sub
  353.     
  354.     Sub BrowseTracksByArtistAndTitle( searchType, a, t )
  355.         a = LCase(Trim(a))
  356.         t = LCase(Trim(t))
  357.         Dim llist, bi, cnt, artist, title, tempMenu, match
  358.         'Retrieve playlist
  359.         ActiveXManager("WinampCOMLib.WinampCOMObj").GetPlayList
  360.         Set llist = New LinkedList
  361.         bi = llist.BackInserter
  362.         For cnt = 0 To ActiveXManager("WinampCOMLib.WinampCOMObj").GetPlayListLength - 1
  363.             artist = LCase(Trim(ActiveXManager("WinampCOMLib.WinampCOMObj").GetArtistbyPosition(cnt)))
  364.             title  = LCase(Trim(ActiveXManager("WinampCOMLib.WinampCOMObj").GetSongTitlebyPosition(cnt)))
  365.             match  = False
  366.             Select Case searchType
  367.                 Case WINAMP_SEARCH_ARTIST_MATCH  If artist = a                                     Then match = True
  368.                 Case WINAMP_SEARCH_ARTIST_SUBSTR If InStr(artist, a) > 0                          Then match = True
  369.                 Case WINAMP_SEARCH_TITLE_MATCH   If title = t                                      Then match = True
  370.                 Case WINAMP_SEARCH_TITLE_SUBSTR  If InStr(title, t) > 0                           Then match = True
  371.                 Case WINAMP_SEARCH_BOTH_MATCH    If artist = a And title = t                      Then match = True
  372.                 Case WINAMP_SEARCH_BOTH_SUBSTR   If InStr(artist, a) > 0 And InStr(title, t) > 0 Then match = True
  373.                 Case WINAMP_SEARCH_ONE_MATCH     If artist = a Or title = t                       Then match = True
  374.                 Case WINAMP_SEARCH_ONE_SUBSTR    If InStr(artist, a) > 0 Or InStr(title, t) > 0  Then match = True
  375.             End Select
  376.             If match Then bi.Item = Array( getSong(cnt), Self & ".PlaySongShowSearch " & cnt )
  377.         Next
  378.         If llist.Count < 1 Then bi.Item = Array( "(No matches!)", "am.Update" )
  379.         Set tempMenu = New ManagedMenu
  380.         tempMenu.SetList llist
  381.         tempMenu.ShowMenu
  382.     End Sub
  383.     
  384. End Class